package com.hexinfo.dmpro.monitor.service;

import com.alibaba.fastjson.JSONObject;
import com.hexinfo.dmpro.monitor.model.YarnMetricsModel;
import com.hexinfo.dmpro.monitor.model.base.MonitorReq;
import com.hexinfo.dmpro.monitor.model.base.MonitorRsp;
import org.springframework.stereotype.Service;

/**
 * @author peng
 * @date 2021/9/28 14:17
 */
@Service
public class YarnMetricsService extends MonitorBaseService<MonitorRsp, MonitorReq> {


    @Override
    protected MonitorReq getReqInfo(MonitorReq monitorReq) {
        return monitorReq;
    }

    @Override
    protected MonitorRsp parse(MonitorRsp monitorRsp) {
        String body = monitorRsp.getBody();
        JSONObject jsonObject = JSONObject.parseObject(body);
        String clusterMetrics = jsonObject.getString("clusterMetrics");
        YarnMetricsModel yarnMetricsModel = JSONObject.parseObject(clusterMetrics, YarnMetricsModel.class);
        monitorRsp.setObj(yarnMetricsModel);
        return monitorRsp;
    }


    @Override
    protected void saveInfo(MonitorRsp monitorRsp) {

    }
}
